#pragma once
#include <functional>
#include <string>
#include <cstring>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include "Log.hpp"
#include "InetAddr.hpp"
using namespace LogModule;

enum ExitCode
{
    NORMAL = 0,
    SOCKET_ERROR,
    BIND_ERROR,
    LISTEN_ERROR,
    FORK_ERROR,
    READ_ERROR,
    WRITE_ERROR,
    USAGE_ERROR,
    CONNECT_ERROR,
    DAEMON_ERROR, 
    EPCREATE_ERROR, 
    EPCTL_ERROR
};

class NoCopy
{
public:
    NoCopy(){}
    NoCopy(const NoCopy&) = delete;
    NoCopy& operator=(const NoCopy&) = delete;
};

void SetNonBlock(int fd)
{
    int fl = fcntl(fd, F_GETFL);
    if(fl == -1)
    {
        LOG(LogLevel::ERROR) << "SetNoBlock: fd[" << fd << "]设置非阻塞失败! ";
        return;
    }
    fcntl(fd, F_SETFL, fl | O_NONBLOCK);
}